﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mimoza.Apps.Console.ViewModel;
using Mimoza.Apps.Console.Commands;
using Mimoza.Apps.Console.Resources;

namespace Mimoza.Apps.Console.View
{
    public partial class ToolBarView : BaseView
    {
        public ToolBarView()
        {
            InitializeComponent();
        }
  
        private void AddCommand2ToolBar(IEnumerable<BaseConsoleCommand> commands, bool left)
        {
            foreach (BaseConsoleCommand cmd in commands)
            {
                if (cmd != null)
                {
                    ToolStripButton button = new ToolStripButton();

                    button.Text = GetCommandText(cmd);
                    button.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
                    button.Enabled = cmd.Enabled;
                    button.Visible = cmd.Visible;
                    button.Tag = cmd;
                    button.Click += new System.EventHandler(this.command_Click);

                    this.toolStrip1.Items.Add(button);
                    cmd.PropertyChanged += new PropertyChangedEventHandler(this.command_PropertyChanged);

                    m_toolStripItemList.Add(button);
                }
            }
        }
        public override void Init(BaseViewModel viewModel)
        {
            m_viewModel = viewModel;

            this.Dock = DockStyle.Fill;

            ToolStripSplitButton containerSpiltButton = new ToolStripSplitButton();
            containerSpiltButton.Text = Resource.ToolBarView_GroupFolder;
            this.toolStrip1.Items.Add(containerSpiltButton);

            AddCommand2Context(m_viewModel, containerSpiltButton);
            AddCommand2ToolBar((m_viewModel as ToolBarViewModel).GetToolBarCommands(0), true);
            AddCommand2ToolBar((m_viewModel as ToolBarViewModel).GetToolBarCommands(1), false);
        }
    }
}
